<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/axios.min.js"></script>
    <script src="../js/vue@2.7.16.js"></script>
</head>

<body>
    <div id="app">
        <h1>app1实例</h1>
        <my-component-name txt1="app1_mycomponent" txt2="app1的标题" msg="app1消息" @myclick="getClick"></my-component-name>
        <span>显示点击内容:{{msg}}</span>
    </div>


    <div id="app2">
        <h1>app2实例</h1>
        <my-component-name txt1="app2_mycomponent" txt2="app2的标题" msg="<span>app2消息</span>"
            @myclick="getClick"></my-component-name>
        <my-component-name2></my-component-name2>
    </div>

    <template id="mybuttontemplate">
        <div>
            <button @click='alertMsg' :id="txt1" :title="txt2">按钮1</button>
            <button @click='alertMsg2'>按钮2</button>
            <span>{{msg}}</span>
        </div>
    </template>

</body>
<script>
    //注册全局组件
    Vue.component('my-component-name', {
        template: "#mybuttontemplate",
        methods: {
            alertMsg: function () {
                this.$emit("myclick", "点击了按钮1", "ninni")
            },
            alertMsg2: function () {
                this.$emit("myclick", "点击了按钮2", "ninni")
            }
        },
        data: function () {
            return {
                msg: "提示框"
            }
        },
        props: ["txt1", "txt2", "msg"],
    });


    Vue.component('my-component-name2', {
       template:"<div>全局组件2</div>",
    });

    var vm = new Vue({
        el: "#app",
        data: {
            msg: "",
        },
        methods: {
            getClick: function (temp) {
                this.msg = temp;

            }
        },
        //注册部分组件
        components: {
            "my-component-name2": {
                template: "<div>部分组件</div>",
            }
        }

    })
    var vm2 = new Vue({
        el: "#app2",
        methods: {
            getClick: function (temp) {
                alert(temp)
            }
        }
    })
</script>

</html>